package com.qf.fmall.shopcart.service.impl;

import com.qf.fmall.shopcart.entity.ShoppingCart;
import com.qf.fmall.shopcart.mapper.ShoppingCartMapper;
import com.qf.fmall.shopcart.service.IShoppingCartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.fmall.shopcart.vo.ShopcartListResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author djl
 * @since 2024-04-28
 */
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements IShoppingCartService {

    @Autowired
    private ShoppingCartMapper shoppingCartMapper;

    @Override
    public List<ShopcartListResponseVo> listByUserId(Integer id) {

        return shoppingCartMapper.selectCartInfoByUserId(id);

    }

    @Override
    public void updateByIdBysql(Integer cartid, Integer number) {

        shoppingCartMapper.updateBySql(cartid,number);

    }

    @Override
    public List<ShopcartListResponseVo> listbycids(String cids) {


        String[] split = cids.split(",");
        Integer[] cidArr = new Integer[split.length];
        for (int i = 0; i < split.length; i++) {
            cidArr[i] = Integer.valueOf(split[i]);
        }
        List<ShopcartListResponseVo> data =  shoppingCartMapper.listbycids(cidArr);
        return data;
    }

    @Override
    public List<ShopcartListResponseVo> listbycids(Integer[] cidArr) {

        List<ShopcartListResponseVo> data =  shoppingCartMapper.listbycids(cidArr);
        return data;
    }
}
